//
//  WJSendMessageViewController.m
//  RenRen
//
//  Created by 杜文杰 on 2018/7/19.
//

#import "WJSendMessageViewController.h"
#import "WJSendMessageCollectionViewCell.h"
#import "ChooseServerTypeViewController.h"

@interface WJSendMessageViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *shopingCollectionView;
@property (nonatomic, strong) NSMutableArray *datamuArray;
@end

@implementation WJSendMessageViewController
/**
 获取服务大分类接口
 参数名    必选    类型    说明
 uid    是    string    uid
 token    是    string    秘钥
 parentcat    是    int    上级分类id，所有一级分类的上级分类id为0
 */
//- (void)getServersList {
//    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=servicecat" parameters:@{@"uid":[UserModel sharedInstanced].userId,@"token":[UserModel sharedInstanced].token,@"parentcat":@0} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
//            //            ShowMessage(@"操作成功");
//            self.datamuArray = responseObject[@"data"];
//            [self.shopingCollectionView reloadData];
//        }else{
//            ShowMessage(@"操作失败");
//        }
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        [self showError:error];
//    }];
//}
- (void)buttonAction
{
//    ProvinceView *view = [[ProvinceView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) selectedHandle:^(NSDictionary *dic) {
//        [self.addressButton setTitle:dic[@"province"] forState:UIControlStateNormal];
//        self.shengId = dic[@"id"];
//        [self getLkDataList];
//    }];
//    [view show];
}
-(instancetype)init{
    self = [super init];
    if(self){
        [self.tabBarItem setImage:[UIImage imageNamed:@"tab-home-default"]];
        [self.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tab-home-enter"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [self.tabBarItem setTitle:@"首页"];
        self.tabBarItem.tag=2;
    }
    return self;
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.title = @"发布服务";
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.shopingCollectionView];
    __weak typeof(self)weakself = self;
    
    [self.shopingCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.view);
        make.left.right.equalTo(weakself.view);
        make.height.mas_equalTo(SCREEN_HEIGHT - SafeAreaTopHeight - SafeAreaBottomHeight);
        //        make.height.mas_equalTo(200);
    }];
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 25)];
    UIButton *button = [[UIButton alloc] initWithFrame:contentView.bounds];
    [button.titleLabel sizeToFit];
//    self.addressButton = button;
    [button setTitle:@"我的发布" forState:UIControlStateNormal];
    button.titleLabel.font = DEF_FontSize_14;
    [button setTitleColor:getColor(textColor) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:contentView];
    self.navigationItem.rightBarButtonItems = @[button2];
}

#pragma mark - UICollectionViewDelegate and UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.datamuArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WJSendMessageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([WJSendMessageCollectionViewCell class]) forIndexPath:indexPath];
    cell.dataDic = self.datamuArray[indexPath.row];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ChooseServerTypeViewController *VC = [[ChooseServerTypeViewController alloc]init];
    VC.hidesBottomBarWhenPushed = YES;
    VC.dataDic = self.datamuArray[indexPath.row];
    [self.navigationController pushViewController:VC animated:NO];
    
}
- (UICollectionView *)shopingCollectionView
{
    if (!_shopingCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 3,100 / HEIGHT_6S_SCALE);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(10 / HEIGHT_6S_SCALE, 0, 0, 0);
        
        _shopingCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _shopingCollectionView.backgroundColor = [UIColor clearColor];
        _shopingCollectionView.bounces = YES;
        _shopingCollectionView.delegate = self;
        _shopingCollectionView.dataSource = self;
        _shopingCollectionView.showsVerticalScrollIndicator = NO;
        _shopingCollectionView.showsHorizontalScrollIndicator = NO;
        _shopingCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_shopingCollectionView registerClass:[WJSendMessageCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([WJSendMessageCollectionViewCell class])];
    }
    
    return _shopingCollectionView;
}
- (NSMutableArray *)datamuArray
{
    if (!_datamuArray) {
        _datamuArray = @[@{@"catico":@"WX20180719-a",@"catname":@"房产信息"},
                         @{@"catico":@"WX20180719-b",@"catname":@"招聘信息"},
                         @{@"catico":@"WX20180719-c",@"catname":@"二手市场"},
                         @{@"catico":@"WX20180719-d",@"catname":@"拼车顺风车"},
                         @{@"catico":@"WX20180719-e",@"catname":@"宠物"},
                         @{@"catico":@"WX20180719-f",@"catname":@"教育培训"},
                         @{@"catico":@"WX20180719-d",@"catname":@"劳务市场"},
                         @{@"catico":@"WX20180719-c",@"catname":@"装修建材"},
                         @{@"catico":@"WX20180719-b",@"catname":@"家政服务"},
                         @{@"catico":@"WX20180719-a",@"catname":@"thinking"}].mutableCopy;
    }
    return _datamuArray;
}
@end

